package app.kotlin_1.adapter

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import app.kotlin_1.R
import app.kotlin_1.activity.GameDetailActivity
import app.kotlin_1.activity.GameKindActivit
import app.kotlin_1.bean.GameBean
import app.kotlin_1.utils.e
import app.kotlin_1.utils.toast
import com.facebook.drawee.view.SimpleDraweeView
import  kotlinx.android.synthetic.main.item_home_new_game.view.*

/**
 * Created by 刘智强 on 2017/9/20.
 * 最新游戏
 *
 */
class HomeNewGameAdapter() : RecyclerView.Adapter<HomeNewGameAdapter.ItemViewHolder>() {
    private var context: Context? = null
    private var gameList: MutableList<GameBean>? = mutableListOf()


    constructor(context: Context, gameList: MutableList<GameBean>) : this() {
        this.context = context
        this.gameList = gameList
    }

    override fun onBindViewHolder(holder: ItemViewHolder?, position: Int) {
        var gameBean: GameBean? = gameList!!.get(position)
        holder!!.tvNewGameName!!.text = gameBean?.name
        holder!!.ivNewGameIcon!!.setImageURI(gameBean?.icon)
        holder!!.itemView.llItem.setOnClickListener { v ->
            val intent = Intent(context, GameDetailActivity::class.java)
            val bundle = Bundle()
            bundle!!.putSerializable("game", gameList!![position])
            intent.putExtras(bundle)
            context!!.startActivity(intent)
        }


    }

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ItemViewHolder {
        return ItemViewHolder(LayoutInflater.from(parent?.context).inflate(R.layout.item_home_new_game, parent, false))
    }

    override fun getItemCount(): Int {
        return gameList!!.size
    }


    inner class ItemViewHolder : RecyclerView.ViewHolder {
        var tvNewGameName: TextView? = null
        var ivNewGameIcon: SimpleDraweeView? = null


        constructor(itemView: View?) : super(itemView) {
            tvNewGameName = itemView!!.tvNewGameName
            ivNewGameIcon = itemView!!.ivNewGameIcon

        }
    }

}

